import { defineStore } from 'pinia'
const template = {
  "id": 'KnowLedge',
  "name": '知识库节点',
  "type": "knowledge",
  "data": {
    "title": "知识库节点",
    "description": "在所选知识中，根据输入变量检索最匹配的信息，并将其作为数组返回。",
    "kbase": {
      "name": "",
      "title": "",
      "strategy": "2",
      "topK": [10],
      "similarityThreshold": [0.6]
    },
    "input": [{
      "ref": "",
      "name": "query",
      "category": "1",
      "value": "",
      "required": true,
    }],
    "output": [{
      "name": "output",
      "type": "5",
      "value":[
        {
          name: 'output',
          type: 'Array<String>',
          subParams: []
        }],
    }]
  }
}
export const useKnowLedgeStore = defineStore({
  id: 'useKnowLedgeStore',
  state: () => ({
    template
  }),
  actions: {
    init(data: any) {
      data.data.kbase.topK = [data.data.kbase.topK];
      data.data.kbase.similarityThreshold = [data.data.kbase.similarityThreshold];
      data.data.input = data.data.input.map((item: any) => {
        item.Options = [{
          label: item.value,
          value: item.value
        }]
        return item
      })
      this.template = { ...data }
    },
    setId(id: string) {
      this.template.id = id;
    },
    updateRef(id: string) {
      this.template.data.input.forEach(item => {
        item.ref = id
      })
    },
    changeFileName(data: any) {
      const { id, name } = data;
      this.template.data.kbase.name = id;
      this.template.data.kbase.title = name
    },
    clearData() {
      this.template.data.input = this.template.data.input.map(item=>{
        item.value = ''
        return item
      })
    }
  }
})
